function PopupOverlay(param) {

	var that = this;
	
	this.j_popup = null;
	this.j_popup_container = null;
	this.j_popup_close = null;
	this.j_popup_overlay = null;
	this.j_popup_trigger = null;
	
	var url_rewrite = false;
	var has_init = false;
	
	function __construct(p) {
	try{
		for(pkey in p) {
			if(pkey[0] != "_") {
				that[pkey] = p[pkey];
			}
		}
		
		that.j_popup_overlay.click(closePopup);
		that.j_popup_close.click(closePopup);
		that.j_popup_trigger.live("click", showPopup);
		
	}catch(err) {
		alert(err);
	}
	}
	
	function simulateShowPopup(popup_data) {
	try{
		document.title += "-simulateShowPopup-";

		if(!jq("body").hasClass("noscroll")) {
			jq("body").addClass("noscroll");
		}

		if(url_rewrite) {
			var history_forword = popup_data.history_forword;
			changeStates({"popup_data" : popup_data}, document.title, history_forword);
		}
		
		var popup_width = popup_data.popup_width;
		var popup_margin_top = popup_data.popup_margin_top;
		var popup_src = popup_data.src;
		if(popup_width) {
			that.j_popup.css({ "width" : popup_width + "px" });
		}
		if(popup_margin_top) {
			that.j_popup.css({ "margin-top" : popup_margin_top + "px" });
		}
		that.j_popup_overlay.show();
		that.j_popup_container.load(popup_src, function() {
			that.j_popup.show();
     	});
		
    }catch(err) {
    	alert(err);
	}
	}
	
	function init(popup_data) {
		var _url_rewrite = popup_data.url_rewrite;
		if(_url_rewrite) {
			url_rewrite = _url_rewrite;
		}
		
		window.onpopstate = function(event) {
			try{
				var historyState = event.state;
				if(historyState && historyState.popup_data !== 'undefined') {
  					simulateShowPopup(historyState.popup_data);
				}
			}catch(err) {
				alert(err);
			}
		};
	}
	
	function showPopup(e) {
	try{
		e.preventDefault();

		if(!jq("body").hasClass("noscroll")) {
			jq("body").addClass("noscroll");
		}
		var popup_trigger = jq(this);
		var popup_data = popup_trigger.data("popup");
		if(!has_init) {
			has_init = true;
			init(popup_data);
		}
		
		if(url_rewrite) {
			var history_forword = popup_data.history_forword;
			changeStates({"popup_data" : popup_data}, document.title, history_forword);
		}
		
		var popup_width = popup_data.popup_width;
		var popup_margin_top = popup_data.popup_margin_top;
		var popup_src = popup_data.src;
		if(popup_width) {
			that.j_popup.css({ "width" : popup_width + "px" });
		}
		if(popup_margin_top) {
			that.j_popup.css({ "margin-top" : popup_margin_top + "px" });
		}
		that.j_popup_overlay.show();
		that.j_popup_container.load(popup_src, function() {
			that.j_popup.show();
     	});
     }catch(err) {
		alert(err);
	}
	}
	
	function closePopup(e) {
	try{
		var target = jq(e.target);
		if(target.is("[data-dom-id=popup-overlay]") || target.is("[data-dom-id=popup] a[href='#popup_close']")) {
			e.preventDefault();
			//history.go(-1);
			document.title += "-document.referrer: " + document.referrer;
			that.j_popup.hide();
			that.j_popup_overlay.hide();
			if(jq("body").hasClass("noscroll")) {
				jq("body").removeClass("noscroll");
			}
		}
	}catch(err) {
		alert(err);
	}
	}

	
    function changeStates(stateObject, title, url) {
    try{
		if (history && history.pushState) {
    		history.pushState(stateObject, title, url);
    	}
	}catch(err) {
		alert(err);
	}
    }
    
    function replaceStates(stateObject, title, url) {
    try{
		if (history && history.replaceState) {
    		history.replaceState(stateObject, title, url);
    	}
	}catch(err) {
		alert(err);
	}
    }
    
	__construct(param);
	
}
